home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / rcs5ap1s.lzh / RCSREV.C < prev    next >
C/C++ Source or Header  |  1991-01-30  |  22KB  |  727 lines

  1. /*
  2.  *                     RCS revision number handling
  3.  */
  4.  
  5. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  6.    Copyright 1990 by Paul Eggert
  7.    Distributed under license by the Free Software Foundation, Inc.
  8.  
  9. This file is part of RCS.
  10.  
  11. RCS is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 1, or (at your option)
  14. any later version.
  15.  
  16. RCS is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with RCS; see the file COPYING.  If not, write to
  23. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25. Report problems and direct all questions to:
  26.  
  27.     rcs-bugs@cs.purdue.edu
  28.  
  29. */
  30.  
  31.  
  32.  
  33.  
  34. /* $Log: rcsrev.c,v $
  35.  * Revision 5.2  1991/01/30  14:21:32  apratt
  36.  * CI with RCS version 5
  37.  *
  38.  * Revision 5.1  91/01/29  17:46:00  apratt
  39.  * Added HEAD_REV code: now you can freeze a configuration with rcs
  40.  * 
  41.  * Revision 5.0  90/08/22  08:13:43  eggert
  42.  * checked in with -k by apratt at 91.01.10.13.15.28.
  43.  * 
  44.  * Revision 5.0  1990/08/22  08:13:43  eggert
  45.  * Remove compile-time limits; use malloc instead.
  46.  * Ansify and Posixate.  Tune.
  47.  * Remove possibility of an internal error.  Remove lint.
  48.  *
  49.  * Revision 4.5  89/05/01  15:13:22  narten
  50.  * changed copyright header to reflect current distribution rules
  51.  * 
  52.  * Revision 4.4  87/12/18  11:45:22  narten
  53.  * more lint cleanups. Also, the NOTREACHED comment is no longer necessary, 
  54.  * since there's now a return value there with a value. (Guy Harris)
  55.  * 
  56.  * Revision 4.3  87/10/18  10:38:42  narten
  57.  * Updating version numbers. Changes relative to version 1.1 actually 
  58.  * relative to 4.1
  59.  * 
  60.  * Revision 1.3  87/09/24  14:00:37  narten
  61.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  62.  * warnings)
  63.  * 
  64.  * Revision 1.2  87/03/27  14:22:37  jenkins
  65.  * Port to suns
  66.  * 
  67.  * Revision 4.1  83/03/25  21:10:45  wft
  68.  * Only changed $Header to $Id.
  69.  * 
  70.  * Revision 3.4  82/12/04  13:24:08  wft
  71.  * Replaced getdelta() with gettree().
  72.  *
  73.  * Revision 3.3  82/11/28  21:33:15  wft
  74.  * fixed compartial() and compnum() for nil-parameters; fixed nils
  75.  * in error messages. Testprogram output shortenend.
  76.  *
  77.  * Revision 3.2  82/10/18  21:19:47  wft
  78.  * renamed compnum->cmpnum, compnumfld->cmpnumfld,
  79.  * numericrevno->numricrevno.
  80.  *
  81.  * Revision 3.1  82/10/11  19:46:09  wft
  82.  * changed expandsym() to check for source==nil; returns zero length string
  83.  * in that case.
  84.  */
  85.  
  86.  
  87.  
  88. /*
  89. #define REVTEST
  90. */
  91. /* version REVTEST is for testing the routines that generate a sequence
  92.  * of delta numbers needed to regenerate a given delta.
  93.  */
  94.  
  95. #include "rcsbase.h"
  96.  
  97. libId(revId, "$Id: rcsrev.c,v 5.2 1991/01/30 14:21:32 apratt Exp $")
  98.  
  99. static struct hshentry *genbranch P((const struct hshentry*,const char*,unsigned,const char*,const char*,const char*,struct hshentries**));
  100.  
  101.  
  102.  
  103.     unsigned
  104. countnumflds(s)
  105.     const char *s;
  106. /* Given a pointer s to a dotted number (date or revision number),
  107.  * countnumflds returns the number of digitfields in s.
  108.  */
  109. {
  110.     register const char *sp;
  111.     register unsigned count;
  112.         if ((sp=s)==nil) return(0);
  113.         if (*sp == '\0') return(0);
  114.         count = 1;
  115.     do {
  116.                 if (*sp++ == '.') count++;
  117.     } while (*sp);
  118.         if (*(--sp) == '.') count--; /*trailing periods don't count*/
  119.         return(count);
  120. }
  121.  
  122.     void
  123. getbranchno(revno,branchno)
  124.     const char *revno;
  125.     struct buf *branchno;
  126. /* Given a non-nil revision number revno, getbranchno copies the number of the branch
  127.  * on which revno is into branchno. If revno itself is a branch number,
  128.  * it is copied unchanged.
  129.  */
  130. {
  131.     register unsigned numflds;
  132.     register char *tp;
  133.  
  134.     bufscpy(branchno, revno);
  135.         numflds=countnumflds(revno);
  136.     if (!(numflds & 1)) {
  137.         tp = branchno->string;
  138.         while (--numflds)
  139.             while (*tp++ != '.')
  140.                 ;
  141.                 *(tp-1)='\0';
  142.         }
  143. }
  144.  
  145.  
  146.  
  147. int cmpnum(num1, num2)
  148.     const char *num1, *num2;
  149. /* compares the two dotted numbers num1 and num2 lexicographically
  150.  * by field. Individual fields are compared numerically.
  151.  * returns <0, 0, >0 if num1<num2, num1==num2, and num1>num2, resp.
  152.  * omitted fields are assumed to be higher than the existing ones.
  153. */
  154. {
  155.     register const char *s1, *s2;
  156.         register int n1, n2;
  157.  
  158.         s1=num1==nil?"":num1;
  159.         s2=num2==nil?"":num2;
  160.  
  161.         do {
  162.                 n1 = 0;
  163.         while (isdigit(*s1))
  164.             n1 = n1*10 + (*s1++ - '0');
  165.                 /* skip '.' */
  166.                 if (*s1=='.') s1++;
  167.  
  168.                 n2 = 0;
  169.         while (isdigit(*s2))
  170.             n2 = n2*10 + (*s2++ - '0');
  171.                 /* skip '.' */
  172.                 if (*s2=='.') s2++;
  173.  
  174.         } while ((n1==n2) && (*s1!='\0') && (*s2!='\0'));
  175.  
  176.         if (((*s1=='\0') && (*s2=='\0')) || (n1!=n2))
  177.                 return (n1 - n2);
  178.         /*now n1==n2 and one of s1 or s2 is shorter*/
  179.         /*give precedence to shorter one*/
  180.         if (*s1=='\0') return 1;
  181.         else           return -1;
  182.  
  183. }
  184.  
  185.  
  186.  
  187. int cmpnumfld(num1, num2, fld)
  188.     const char *num1, *num2;
  189.     unsigned fld;
  190. /* compares the two dotted numbers at field fld and returns
  191.  * num1[fld]-num2[fld]. Assumes that num1 and num2 have at least fld fields.
  192.  * fld must be positive.
  193. */
  194. {
  195.     register const char *s1, *s2;
  196.     register unsigned n1, n2;
  197.  
  198.     s1 = num1;
  199.     s2 = num2;
  200.         /* skip fld-1 fields */
  201.     for (n1 = fld;  (--n1);  ) {
  202.         while (*s1++ != '.')
  203.             ;
  204.         while (*s2++ != '.')
  205.             ;
  206.     }
  207.         /* Now s1 and s2 point to the beginning of the respective fields */
  208.         /* compute numerical value and compare */
  209.         n1 = 0;
  210.     while (isdigit(*s1))
  211.         n1 = n1*10 + (*s1++ - '0');
  212.         n2 = 0;
  213.     while (isdigit(*s2))
  214.         n2 = n2*10 + (*s2++ - '0');
  215.     return n1<n2 ? -1 : n1==n2 ? 0 : 1;
  216. }
  217.  
  218.  
  219.     int
  220. compartial(num1, num2, length)
  221.     const char *num1, *num2;
  222.     unsigned length;
  223.  
  224. /*   compare the first "length" fields of two dot numbers;
  225.      the omitted field is considered to be larger than any number  */
  226. /*   restriction:  at least one number has length or more fields   */
  227.  
  228. {
  229.     register const char *s1, *s2;
  230.         register        int     n1, n2;
  231.  
  232.  
  233.         s1 = num1;      s2 = num2;
  234.         if ( s1==nil || *s1 == '\0' ) return 1;
  235.         if ( s2==nil || *s2 == '\0' ) return -1;
  236.  
  237.     for (;;) {
  238.             n1 = 0;
  239.         while (isdigit(*s1))
  240.         n1 = n1*10 + (*s1++ - '0');
  241.             if ( *s1 == '.' ) s1++;    /*  skip .   */
  242.  
  243.             n2 = 0;
  244.         while (isdigit(*s2))
  245.         n2 = n2*10 + (*s2++ - '0');
  246.             if (*s2 == '.') s2++;
  247.  
  248.         if ( n1 != n2 ) return n1-n2;
  249.         if ( --length == 0 ) return 0;
  250.         if ( *s1 == '\0' ) return 1;
  251.         if ( *s2 == '\0' ) return -1;
  252.     }
  253. }
  254.  
  255.  
  256. char * partialno(rev1,rev2,length)
  257.     struct buf *rev1;
  258.     const char *rev2;
  259.     register unsigned length;
  260. /* Function: Copies length fields of revision number rev2 into rev1.
  261.  * Return rev1's string.
  262.  */
  263. {
  264.     register char *r1;
  265.  
  266.     bufscpy(rev1, rev2);
  267.     r1 = rev1->string;
  268.         while (length) {
  269.         while (*r1!='.' && *r1)
  270.             ++r1;
  271.         ++r1;
  272.                 length--;
  273.         }
  274.         /* eliminate last '.'*/
  275.         *(r1-1)='\0';
  276.     return rev1->string;
  277. }
  278.  
  279.  
  280.  
  281.  
  282.     static void
  283. store1(store, next)
  284.     struct hshentries ***store;
  285.     struct hshentry *next;
  286. /*
  287.  * Allocate a new list node that addresses NEXT.
  288.  * Append it to the list that **STORE is the end pointer of.
  289.  */
  290. {
  291.     register struct hshentries *p;
  292.  
  293.     p = ftalloc(struct hshentries);
  294.     p->first = next;
  295.     **store = p;
  296.     *store = &p->rest;
  297. }
  298.  
  299. struct hshentry * genrevs(revno,date,author,state,store)
  300.     const char *revno, *date, *author, *state;
  301.     struct hshentries **store;
  302. /* Function: finds the deltas needed for reconstructing the
  303.  * revision given by revno, date, author, and state, and stores pointers
  304.  * to these deltas into a list whose starting address is given by store.
  305.  * The